// pages/test/test.js

import instance from '../../utils/http'
Page({
  async handler() {
    // handler() {
    //   instance.request({
    //     url: '/index/findBanner',
    //     method: 'GET'
    //   })
    // //     .then((res) => {
    //       console.log(res);
    //     })
    // }
    const res = await instance.get('/index/findBanner111')
    console.log(res)
  },
  handler1() {
    wx.request({
      url: 'https://gmall-prod.atguigu.cn/mall-api/index/findBanner',
      method: 'GET',
      // timeout: 100, 测试网络超时，需要调整网络
      success: (res) => {
        console.log('只要成功接收到服务器返回，不管状态是多少，都会进入 success 回调')
        console.log(res)
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },
  async allHandler() {
    // await instance.get('/index/findBanner')
    // await instance.get('/index/findCategory1')
    // await instance.get('/index/findBanner')
    // await instance.get('/index/findCategory1')
    //同时发送请求不会造成页面渲染速度
    // await Promise.all([instance.get('/index/findBanner'), instance.get('/index/findCategory1'), instance.get('/index/findBanner'), instance.get('/index/findCategory1')])
    const res = await instance.all(instance.get('/index/findBanner'), instance.get('/index/findCategory1'), instance.get('/index/findBanner'), instance.get('/index/findCategory1'))
    console.log(res);
  }
})